#include "StringUtility.h"

#include <charconv>

#include <iostream>

namespace StringUtility {
const std::string EMPTY_STRING;

constexpr ssize_t MAX_BYTE_WIDTH = 8;
constexpr ssize_t BATCH_FORMAT_COUNT = 8;


StringVector& split(const std::string& str, const std::string& splitter, StringVector& result) {
    const std::string::size_type splitterLength = splitter.size();
    std::string::size_type prevPos = 0, pos = 0;

    while (std::string::npos != (pos = str.find(splitter, prevPos))) {

        result.emplace_back(&str[prevPos], &str[pos]);

        prevPos = pos + splitterLength;
    }
    result.emplace_back(&str[prevPos], &str[str.size()]);

//            for (std::string& strRef : result) std::cout << '['<< strRef << ']';

    return result;
}


std::string& stringToBinary(const std::string& inputString, std::string& resultData) {
    const size_t length = inputString.size();
    const char *pend = inputString.data() + length;
    uint8_t resultByte = 0;
    resultData.reserve((length + 1) << 1);
    for (const char * pointer = inputString.data(); pointer != pend; pointer += 2) {
        std::from_chars(pointer, pointer + 2, resultByte, 16);

        resultData.append(1,  resultByte);
    }

    return resultData;
}


}
